package com.didispace;

import java.util.List;

import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.didispace.domain.p.user.User;
import com.didispace.domain.p.user.UserRepository;

@RestController
public class UserController {
	
	@Autowired
	private UserRepository userRepository;
	
	@RequestMapping("/save")
	public void save() throws Exception {

		userRepository.save(new User("aaa", 10));
		userRepository.save(new User("bbb", 20));
		userRepository.save(new User("ccc", 30));
		userRepository.save(new User("ddd", 40));
		
		System.out.println(userRepository.findAll().size());

	}
	
	
	@RequestMapping("/deleteByUser")
	public void deleteByUser() throws Exception {

		userRepository.delete(3L);
		System.out.println(userRepository.findAll().size());

	}
	
	@ResponseBody
	@RequestMapping("/search")
	public List<User> search() throws Exception {

		return userRepository.findAll();

	}
	
}
